document.querySelectorAll('.commstar').forEach(commstar => {  
    commstar.addEventListener('click', (event) => {  
        if (event.target.classList.contains('star')) {  
            const rating = event.target.getAttribute('data-value');  
            commstar.setAttribute('data-rating', rating);  
            commstar.querySelector('.star-info').textContent = `${rating}分`;  
            updateStars(commstar); // 更新星星的展示  
        }  
    });  
});  

function updateStars(commstar) {  
    const rating = parseInt(commstar.getAttribute('data-rating'));  
    const stars = commstar.querySelectorAll('.star');  
    stars.forEach((star, index) => {  
        star.style.backgroundPosition = index+1 > rating ? '0 0' : '0 -16px'; // 更新星星状态  
    });  
}